package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.goods.vo.GoodsListFromTopicVO;
import com.cskaoyan.bean.param.BaseParam;
import com.cskaoyan.bean.po.MarketTopic;
import com.cskaoyan.bean.topic.TopicDate;
import com.cskaoyan.bean.topic.TopicDateById;
import com.cskaoyan.service.GoodsService;
import com.cskaoyan.service.TopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("admin/topic")
public class TopicController {

    @Autowired
    TopicService topicService;

    @Autowired
    GoodsService goodsService;

    /**
     * 推广管理，专题管理的查询功能
     *
     * @param  “page=1&limit=20&sort=add_time&order=desc”
     * @return
     */
    @GetMapping("list")
    public BaseRespVo list(BaseParam baseParam,String title,String subtitle){

        TopicDate topicDate = topicService.query(baseParam,title,subtitle);

        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrno(0);
        baseRespVo.setErrmsg("成功");
        baseRespVo.setData(topicDate);
        return baseRespVo;

    }

    @PostMapping("create")
    public BaseRespVo create( @RequestBody() MarketTopic marketTopic){

        MarketTopic marketTopic1 = topicService.insert(marketTopic);

        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setData(marketTopic1);
        baseRespVo.setErrmsg("成功");
        baseRespVo.setErrno(0);
        return baseRespVo;
    }

    @GetMapping("read")
    public BaseRespVo read(String id){

        TopicDateById topicDate = topicService.queryById(id);

        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setData(topicDate);
        baseRespVo.setErrmsg("成功");
        baseRespVo.setErrno(0);
        return baseRespVo;
    }


    @PostMapping("update")
    public BaseRespVo update(@RequestBody() MarketTopic marketTopic){

        MarketTopic marketTopic1 = topicService.update(marketTopic);

        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setData(marketTopic1);
        baseRespVo.setErrno(0);
        baseRespVo.setErrmsg("成功");
        return baseRespVo;
    }

    @PostMapping("delete")
    public BaseRespVo delete(@RequestBody() MarketTopic marketTopic){

        topicService.deleteById(marketTopic);
        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrno(0);
        baseRespVo.setErrmsg("成功");
        return baseRespVo;
    }

}
